package com.soulkun.smarthome.ui.main.home.dialog

import android.view.View
import android.view.ViewGroup
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppDialogMainHomeDeviceCommandTimeBinding
import com.soulkun.smarthome.ui.main.home.viewmodel.AppMainHomeDeviceCommandViewModel
import soulkun.library.mvvm.component.BaseDataBindingDialogFragment
import soulkun.library.utils.toPx
import soulkun.library.utils.toast

class AppMainHomeDeviceCommandTimeDialog(private val commandViewModel: AppMainHomeDeviceCommandViewModel) :
    BaseDataBindingDialogFragment<AppDialogMainHomeDeviceCommandTimeBinding>() {

    override fun setLayout(): Int {
        return R.layout.app_dialog_main_home_device_command_time
    }

    override fun doOnViewCreated() {
        requireDialog().window?.run {
            setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        }
        isCancelable = false
        requireDataBinding().onClickListener = View.OnClickListener {
            when (it.id) {
                R.id.tv_main_home_device_command_time_text_cancel -> {
                    dismiss()
                }
                R.id.tv_main_home_device_command_time_text_determine -> {
                    requireDataBinding().tpMainHomeDeviceCommandTimePickerTime.run {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            commandViewModel.selectTimeOutLiveData.value = hour * 60 * 60 + minute * 60
                        }else{
                            commandViewModel.selectTimeOutLiveData.value = currentHour * 60 * 60 + currentMinute * 60
                        }
                        dismiss()
                    }
                }
            }
        }
    }

    override fun doOnResume() {
    }

    override fun doOnDismiss() {
    }

    override fun doOnDestroyView() {
    }

}